{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "b8a57af3-1280-4a11-a63f-c606d5ca5938",
   "metadata": {},
   "source": [
    "将CPLFW和CALFW融合到训练集当中  \n",
    "记得在融合之后重新生成cls_train.txt  同时对训练参数num_train进行修改"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "ed36bd50-9257-405f-ab1a-f71222eecd57",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import glob"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "8c4426b5-9c01-4af5-973c-f97c31d1f272",
   "metadata": {},
   "outputs": [],
   "source": [
    "images_list = glob.glob('images/*')  # CPLFW or CALFW的人名文件夹所在路径\n",
    "train_list = glob.glob('dataset/train/*')\n",
    "train_path = 'dataset/train/'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "1b5b7855-fcac-42cb-a092-1da229d633fd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'images/Aaron_Eckhart_0001.jpg'"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "images_list[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "dd02e403-ae57-42b7-baa8-9c3c24c21137",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'dataset/train/Salma_Hayek'"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_list[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "9f8e9f5b-6e77-4efd-bafe-48e0b6712da1",
   "metadata": {},
   "outputs": [],
   "source": [
    "train_name_list = []\n",
    "for item in  train_list:\n",
    "    train_name_list.append(item.split('/')[-1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "208c9b49-9f97-4fe3-852a-b85ace00dcf6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Salma_Hayek'"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_name_list[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "b33659b3-5eff-47e1-a680-d588c50f9d62",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Aaron_Eckhart'"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name = images_list[0].split('/')[-1].split('.')[0]\n",
    "name = name.split('_')\n",
    "del name[-1]\n",
    "image_name = '_'.join(name)\n",
    "image_name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "eca43e46-a76a-40be-bab0-2db5e1724f8b",
   "metadata": {},
   "outputs": [],
   "source": [
    "images_name_list = []\n",
    "for item in images_list:\n",
    "    name = item.split('/')[-1].split('.')[0]\n",
    "    name = name.split('_')\n",
    "    del name[-1]\n",
    "    image_name = '_'.join(name)\n",
    "    if image_name in train_name_list:\n",
    "        os.system('cp '+item+' '+train_path+image_name)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
